import time

from selenium.webdriver.support.select import Select
from selenium import webdriver
from selenium.webdriver.common.by import By

# 1.打开浏览器



# 创建浏览器对象
driver = webdriver.Chrome()
# 2.输入访问地址（URL）
url = r"E:\python_test\ui自动化测试\注册实例.html"
driver.get(url)
# 放大浏览器页面
driver.maximize_window()
time.sleep(3)
# 案例：打开‘注册实例.html’页面，完成以下操作
# 1). 填写主页面的注册信息
driver.find_element(By.CSS_SELECTOR, "#user").send_keys("admin")        #用户名
driver.find_element(By.CSS_SELECTOR, "#password").send_keys("123456")   #密码
driver.find_element(By.CSS_SELECTOR, "#tel").send_keys("13012345678")   #电话
driver.find_element(By.CSS_SELECTOR, "#email").send_keys("1008611@qq.com")  #邮箱

# 1.获取‘表单综合实例.html’当前窗口句柄
# 目的：判断只要不是当前窗口句柄，就一定是新的窗口句柄
current_handle = driver.current_window_handle
print("综合实例当前窗口句柄：", current_handle)

# 3. 获取所有窗口句柄
handles = driver.window_handles
print("所有窗口句柄：", handles)

# 4. 获取注册A页面对应的窗口句柄，并切
# 判断 不是 '当前窗口句柄'
for i in handles:
    if i != current_handle:
        # 切换
        driver.switch_to.window(i)
        # 用户名
        driver.find_element(By.CSS_SELECTOR, "#userA").send_keys("adminA")
        # # 密码
        driver.find_element(By.CSS_SELECTOR, "#passwordA").send_keys("123456")
        # 电话号码
        driver.find_element(By.CSS_SELECTOR, "#telA").send_keys("15011111111")
        # 电子邮件
        driver.find_element(By.CSS_SELECTOR, "#emailA").send_keys("123456@qq.com")

time.sleep(3)
driver.quit()